package com.haiyangwang1.lesson8.ex1;

public class Account {
    private int accountNumber;
    private double balance;
    //存钱方法
    public void desposit(double money){
        this.balance = this.balance + money;
    }

    public double getBalance() {
        return balance;
    }

    public int getAccountNumber() {
        return accountNumber;
    }
    //取钱方法
    public void withdraw(double money) throws BankException{
        if(this.balance>=money){
            this.balance=this.balance-money;
        }else {
            double needs=money-this.balance;
            throw new BankException("余额不足,",needs);//如果钱不正确才抛出异常   要人为的抛出
        }
    }
}
